package educrypt.gui.ctr;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import educrypt.commons.util.Util;
import educrypt.gui.view.AboutView;
import educrypt.gui.view.MainView;
import educrypt.i18n.Messages;

public class AboutCtr implements ActionListener {

	MainView view;
	AboutView aboutView;

	public AboutCtr(MainView view) {
		this.view = view;
		this.aboutView = view.getAboutPanel();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String command = e.getActionCommand();
		if (command.equals(AboutView.LANG_ENGLISH)) {
			if (!Messages.getLocale().getLanguage().equals(Messages.LANG_EN)) {
				changeLanguage(Messages.LANG_EN);
			}
		}
		if (command.equals(AboutView.LANG_SPANISH)) {
			if (!Messages.getLocale().getLanguage().equals(Messages.LANG_ES)) {
				changeLanguage(Messages.LANG_ES);
			}
		}
	}

	private void changeLanguage(String language) {
		int option = aboutView.showLanguageChangeConfirmation();
		if (option == 0) {
			try {
				Util.restartApplication(null, new String[] { language });
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
